<?php

// Acceso restringido
defined('JL') or die('Acceso restringido');

/**
 * SectionsController
 * 
 * @package JL Panel
 * @author JLQ
 * @copyright 2009
 * @version 1.0
 * @access public
 */
class ContactController extends JLControllerBase {

    private $config = null;
    private $path = "Contact";
    private $title = "Système d'Actualisation CSME > Contact";
    private $data = null;

    /**
     * ContactController::getContact()
     * 
     * @return
     */
    function getContact() {
        $id = $_POST['_id'];

        require JLPATH_MODELS . DS . "ContactModel.php";
        $contacts = new ContactModel();
        $contact = $contacts->getContactById($id);

        $var_cont_nom = $contact['var_cont_nom'];
        $var_cont_tel = $contact['var_cont_tel'];
        $var_status = $contact['var_cont_status'];
        $var_cont_email = $contact['var_cont_email'];
        $int_id_state = $contact['int_id_state'];

        echo $var_cont_nom . "_%_" . $var_cont_tel . "_%_" . $var_status . "_%_" . $var_cont_email . "_%_" . $int_id_state;
    }

    /**
     * ContactController::updateContact()
     * 
     * @return
     */
    function updateContact() {
        $id = $_POST['_id'];
        $var_cont_nom = $_POST['_var_cont_nom'];
        $var_cont_tel = $_POST['_var_cont_tel'];
        $var_cont_status = $_POST['_var_status'];
        $var_cont_tel = $_POST['_var_cont_tel'];
        $var_cont_email = $_POST['_var_cont_email'];
        $int_id_state = $_POST['_int_id_state'];
        $int_id_sections_view = $_POST['_int_id_sections_view'];

        require JLPATH_MODELS . DS . "ContactModel.php";
        $contacts = new ContactModel();

        $_true = $contacts->updateContact($id, $int_id_sections_view, $var_cont_nom, $var_cont_tel, $var_cont_status, $var_cont_email, $int_id_state);

        if ($_true)
            echo "Données sauvegarder avec succès.";
        else
            echo "";
    }

    /**
     * ContactController::insertContatc()
     * 
     * @return
     */
    function insertContact() {
        $var_cont_nom = $_POST['_var_cont_nom'];
        $var_cont_tel = $_POST['_var_cont_tel'];
        $var_status = $_POST['_var_status'];
        $var_cont_tel = $_POST['_var_cont_tel'];
        $var_cont_email = $_POST['_var_cont_email'];
        $int_id_state = $_POST['_int_id_state'];
        $int_id_sections_view = $_POST['_int_id_sections_view'];

        require JLPATH_MODELS . DS . "ContactModel.php";
        $contacts = new ContactModel();
        $_true = $contacts->insertContact($int_id_sections_view, $var_cont_nom, $var_cont_tel, $var_status, $var_cont_email, $int_id_state);

        if ($_true)
            echo "Données sauvegarder avec succès.";
        else
            echo "";
    }

    /**
     * ContactController::deleteContact()
     * 
     * @return
     */
    function deleteContact() {
        $ids = $_POST['_ids'];
        $ides = explode(",", $ids);
        require JLPATH_MODELS . DS . "ContactModel.php";
        $contacts = new ContactModel();

        $i = 0;
        foreach ($ides as $id) {
            $_true = $contacts->deleteContact($id);
            if (!$_true)
                break;

            $i++;
        }
        $nodelete = count($ides) - $i;

        if (!$_true) {
            echo $i . "  Donnée(s) effacer \n$nodelete donnée(s) n'a pu être effacer. Veuillez changer l'état à Provisoire.";
        }
        else
            echo $i . "  Donnée(s) effacer";
    }

}